<?php
class Core_View_Helper_CategoryBuilder extends Zend_View_Helper_Abstract{

	private $_isFirst = true;
    public function __construct()
	{
	}

    /**
	 *
	 * @param array $list
	 * @return string 
	 */
    public function categoryBuilder(array $list, $parent_name = ''){		
		if( $this->_isFirst )
		{
			$html = '<ol class="list-categories">';
			$this->_isFirst = false;
		}
		else
		{
			$html = '<ol>';
		}
		if( empty($parent_name) )
		{
			$parent_name = $this->view->translate('CATEGORY_ROOT');
		}
		foreach ($list as $category){
			$html .= '<li>';
			$html .= $this->view->partial('category/template/an-item.phtml',array(
						'category'		=> $category,
						'parent_name'	=> $parent_name,
						'is_first'		=> $this->_isFirst
					));
			if (array_key_exists('children', $category)){
				$html .= $this->categoryBuilder($category['children'],$category['name']);
			}
			$html .= '</li>';
		}
		$html .= '</ol>';
		return $html;
	}
}